/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * busquedaUsuario.java
 *
 * Created on 24/11/2010, 01:05:21 PM
 */

package GUI.clinica;


import GUI.clinica.clinica;
import javax.swing.JOptionPane;
import cprincipal.*;
import Persistencia.*;
import venehealthfinal.Validar;
/**
 *
 * @author marcelo
 */
public class busquedaPaciente extends javax.swing.JFrame {

    /** Creates new form busquedaUsuario */
    private boolean resultado = false;
    PacienteXml datosPac=new PacienteXml();

    public busquedaPaciente() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        LabelCedula = new javax.swing.JLabel();
        TxtCedulaPaciente = new javax.swing.JTextField();
        BotonBuscar = new javax.swing.JButton();
        BotonRegresar = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel1.setForeground(new java.awt.Color(255, 0, 0));
        jLabel1.setText("Busqueda de Paciente");

        LabelCedula.setFont(new java.awt.Font("Tahoma", 0, 12));
        LabelCedula.setText("Cedula de Paciente:");

        TxtCedulaPaciente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TxtCedulaPacienteActionPerformed(evt);
            }
        });

        BotonBuscar.setText("Buscar");
        BotonBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotonBuscarActionPerformed(evt);
            }
        });

        BotonRegresar.setText("Regresar ");
        BotonRegresar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotonRegresarActionPerformed(evt);
            }
        });

        jButton1.setText("Nuevo");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(29, 29, 29)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addGap(40, 40, 40))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(LabelCedula)
                                .addGap(18, 18, 18)
                                .addComponent(TxtCedulaPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(10, 10, 10))))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(BotonBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(BotonRegresar)))
                .addContainerGap(125, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(LabelCedula, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(TxtCedulaPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(BotonBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(BotonRegresar))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void TxtCedulaPacienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TxtCedulaPacienteActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_TxtCedulaPacienteActionPerformed

    private void BotonRegresarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotonRegresarActionPerformed
            clinica ventana =  new clinica();
           ventana.setVisible(true);
           this.dispose();
    }//GEN-LAST:event_BotonRegresarActionPerformed

    private void BotonBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotonBuscarActionPerformed
    if (TxtCedulaPaciente.getText().isEmpty()){ /*&& (!TxtNombre.getText().isEmpty()) && (!TxtApellido.getText().isEmpty()) && (!TxtAnioNac.getText().isEmpty()) && (!TxtLocalidad.getText().isEmpty()) && (!TxtNumeroColegiatura.getText().isEmpty()) && (!TxtUniversidadEgreso.getText().isEmpty()) && (!TxtEstudiosEspeciales.getText().isEmpty()) && (!TxtEspecialidad.getText().isEmpty()) && (!TxtDisponibilidad.getText().isEmpty()) && (!TxtHoraEntrada.getText().isEmpty()) && (!TxtHoraSalida.getText().isEmpty())*/
            JOptionPane.showMessageDialog(null, "Error, campo invalidos", "Debe indicar un numero de cedula valido", JOptionPane.ERROR_MESSAGE);
        } else {
            int valor = Validar.ValidarEntero(TxtCedulaPaciente.getText(), "Cédula no es numérica");
            if (valor == 1) {
               Paciente pac = datosPac.buscarPaciente(Integer.parseInt(TxtCedulaPaciente.getText()));
                if (pac == null) {
                  JOptionPane.showMessageDialog(null, "Paciente no Existe", "Error cédula no encontrada", JOptionPane.ERROR_MESSAGE);
                } else {
                    informacionPaciente ventana =  new informacionPaciente(pac);
                    ventana.setVisible(true);
                    this.dispose();
                }
        }
       }
    }//GEN-LAST:event_BotonBuscarActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        if (TxtCedulaPaciente.getText().isEmpty()){
              JOptionPane.showMessageDialog(null, "Error, campo invalidos", "Debe indicar un numero de cedula valido", JOptionPane.ERROR_MESSAGE);
        } else {
            System.out.println("Antes de validar");
            int valor = Validar.ValidarEntero(TxtCedulaPaciente.getText(), "Cédula no es numérica");
            System.out.println("Despues de validar");
            if (valor == 1) {
               System.out.println("Entro en el ciclo");
               Paciente pac = new Paciente();
                    pac.setCedula(Integer.parseInt(TxtCedulaPaciente.getText()));
                    informacionPaciente ventana =  new informacionPaciente(pac);
                    ventana.setVisible(true);
                    this.dispose();
                }
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new busquedaPaciente().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BotonBuscar;
    private javax.swing.JButton BotonRegresar;
    private javax.swing.JLabel LabelCedula;
    private javax.swing.JTextField TxtCedulaPaciente;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    // End of variables declaration//GEN-END:variables

}
